package com.hzw.saas.api.template.enums;

import java.util.Objects;

import org.springframework.util.Assert;

/**
 * 模板模块
 *
 * @author zzl
 * @since 09/06/2021
 */
public enum TemplateTypeEnum {

    PROJECT_APPLY(1, "项目审批"),
    CUSTOMER_MANAGER(2, "客户管理"),
    ;

    private final Integer type;
    private final String text;

    TemplateTypeEnum(Integer type, String text) {
        this.type = type;
        this.text = text;
    }

    public Integer getType() {
        return type;
    }

    public String getText() {
        return text;
    }

    public static String validText(Integer type) {
        TemplateTypeEnum instance = instance(type);
        return Objects.isNull(instance) ? "" : instance.getText();
    }

    public static void assertValid(Integer type) {
        TemplateTypeEnum instance = instance(type);
        Assert.notNull(instance, String.format("模板类型未找到: %s", type));
    }

    public static TemplateTypeEnum instance(Integer type) {
        for (TemplateTypeEnum value : TemplateTypeEnum.values()) {
            if (Objects.equals(value.getType(), type)) {
                return value;
            }
        }
        return null;
    }
}
